<extend name="Public:mainbase" />
<block name="content">
<link rel="stylesheet" href="__PUBLIC__/css/bootstrap-switch.min.css">
<script src="__PUBLIC__/js/bootstrap-switch.min.js" type="text/javascript"></script>

<form action="" method="post">
<table width="98%" border="0" align="center" class="table table-bordered">
  
  <tr> 
    <td height="26" colspan="2" bgcolor="#FFFFFF" background="__PUBLIC__/images/tbg.gif" style="padding-left:10px;">
	<strong>用户注册设置</strong>    </td>
  </tr>
  <tr bgcolor="#FFFFFF"> 
    <td width="41%" height="24">用户注册类型：<br> </td>
    <td width="59%">
    	<input class="np" type="radio" value="1" name="reg_type" <eq name="regType" value="1">checked</eq>>
      开放注册 &nbsp;&nbsp;&nbsp;&nbsp;
     <!-- <input class="np" type="radio" value="2" name="reg_type" <eq name="regType" value="2">checked</eq>>
      邀请注册 &nbsp;&nbsp;&nbsp;&nbsp;-->
      <input class="np" type="radio" value="0" name="reg_type" <eq name="regType" value="0">checked</eq>>
      关闭注册
    </td>
  </tr>
  <tr bgcolor="#F9FCEF"> 
    <td height="37" colspan="2" align="center">

		 <button type='submit' class="btn btn-danger btn-sm">确定</button>
            　&nbsp;
		 <button type='reset' class="btn btn-default btn-sm">取消</button></td>
  </tr>  
</table>
</form>
<eq name="regType" value="1">
    <form action="{:U('update_reg_config')}" method="post">
    <div class="panel panel-default">
        <div class="panel-heading">
            <ul class="nav nav-tabs nav-pills">
                <li role="presentation"><a href="javascript:void(0)">详细设置：</a></li>
                <li role="presentation" <eq name="client_type" value="IOS">class="active"</eq>><a href="{:U(reg_setup)}?clientType=IOS">IOS</a></li>
                <li role="presentation" <eq name="client_type" value="ANDROID">class="active"</eq>><a href="{:U(reg_setup)}?clientType=ANDROID">Android</a></li>
            </ul>
        </div>
        <div class="panel-body">

                <table style="width:50%" border="0" align="center" class="table table-bordered">
                    <tr bgcolor="#FFFFFF">
                        <th width="41%" height="24" align="right" style="text-align: right">版本</th>
                        <th width="49%">是否开启</th>
                        <th width="10%"></th>
                    </tr>
                    <volist name="list" id="vo">
                    <tr bgcolor="#FFFFFF">
                        <td align="right" valign="center">V{$vo.version}</td>
                        <td valign="center" >
          <!--                  <input type="radio" name="version[{$client_type}][{$vo.id}]" value="1" <eq name="vo.can_reg" value="1">checked</eq>> 开启
                            <input type="radio" name="version[{$client_type}][{$vo.id}]" value="0" <eq name="vo.can_reg" value="0">checked</eq>> 关闭-->

                                <input type="checkbox" data-id="{$vo.id}" name="version[{$client_type}][{$vo.id}]" value="1" <eq name="vo.can_reg" value="1">checked</eq> />
                        </td>
                        <td align="center" class="delversion"  valign="center"><a href="javascript:void(0)" data-id="{$vo.id}" title="删除 {$vo.version} 版本"><span class="glyphicon glyphicon-remove"></span></a></td>
                    </tr>
                    </volist>
                    <tr bgcolor="#F9FCEF">
                        <td height="37" colspan="3" align="center">
                            <button type='button' class="btn btn-info btn-sm" data-toggle="modal" data-target="#newVer"><span class="glyphicon glyphicon-plus"></span> 添加新版本</button>
                    </tr>
                </table>
        </div>

    </div>
    </form>
</eq>
<div class="alert alert-info alert-dismissible fade"  id='infostext' role="alert">
      <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
      <strong></strong>
    </div>
    <div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="添加新版本" id="newVer">
        <div class="modal-dialog">
            <div class="modal-content">
                <form method="post" action="{:U('newVersion')}" style="padding:15px"  class="form-inline" id="addNewVersionForm">
                    <label for="newversion">输入新的版本号：</label>
                    <input type="text" name="version" id="newversion"  class="form-control" placeholder="请填写不带V的版本号">
                    <input type="hidden" name="client_type" value="{$client_type}">
                    <button type="submit" class="btn btn-danger">确定</button>
                </form>
            </div>
        </div>
    </div>
    <script>
        $('#addNewVersionForm').submit(function(){
            var vesion=$('#newversion').val();
            var re=/^(\d+\.?)+$/;
            if(!re.test(vesion)){
                alert('请填写正确的版本号！');
                return false;
            }
        })
        $('[type=checkbox]').wrap('<div class="switch switch-small">').parent().bootstrapSwitch();
        $('[type=checkbox]').on('switchChange.bootstrapSwitch', function(event, state) {
            var obj=this;
            var type = (state == true) ? 1 : 0;
            var id=$(obj).data('id');
            $.get("{:U('ajax_set_reg')}?id="+id+"&state="+type,function(data){
                if(data==0){
                    location.reload();
                }
            })
        });

        $('.delversion a').click(function(){
            if(confirm("是否确定删除此版本？")){
                var obj=this;
                $.get("{:U('ajax_del_version')}?id="+$(obj).data("id"),function(data){
                    if(data==1){
                        $(obj).parents('tr').remove();
                    }
                })
            }
        });
    </script>
</block>